package com.example.demo.design.demo20_iterator;

import java.util.List;

/**
 * Created by 蔡超 on 2018/10/4.
 */
public class ConcreteIterator implements Iterator {

    private int index;
    private Aggregate aggregate;

    public ConcreteIterator(Aggregate aggregate) {
        this.aggregate = aggregate;
    }

    @Override
    public boolean hasNext() {
        if(index >= aggregate.getSize()){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public Object next() {
        Object obj = aggregate.get(index);
        index++;
        return obj;
    }
}
